<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-button type="danger" round @click="BatchCancelled()">批量取消</el-button>
                <el-input placeholder="档案名/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="mini" current-row-key="id" :data="dataList" ref="checkbox"
                      @selection-change="handleSelection">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" sortable align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" sortable align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center" align="left" width="200%">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="affirmOrder(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" @click="cancelOrder(scope.row)">取消预约</el-button>
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-button type="text" size="mini" @click="handleDeletes()">批量取消</el-button>
            <el-table size="small" current-row-key="id" :data="dataList" @selection-change="selectionChange" ref="checkBoxData" stripe highlight-current-row>
                <el-table-column type="selection" ></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="200%">
                    <template slot-scope="scope" >
                        <el-button type="text" size="mini" @click="">确定预约</el-button>
                        <el-button size="mini" type="text" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next,sizes,jumper"
                        layout="total, prev, pager, next, sizes, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约列表" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="预约基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="预约日期">
                                            <span class="demonstration">
                                            <el-date-picker
                                                    v-model="formData.orderDate"
                                                    @change="getDateTime"
                                                    value-format="yyyy-MM-dd HH:mm:ss"
                                                    type="datetime"
                                                    placeholder="选择日期时间">
                                            </el-date-picker>
                                                </span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="档案号">
                                                <el-input v-model="formData.fileNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="23">
                                            <el-form-item label="手机号码">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="预约类型">
                                                <el-select v-model="formData.orderType">
                                                    <el-option label="电话预约" value="电话预约"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                <el-dialog title="新建" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs type="card">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="预约日期">
                                            <el-date-picker
                                                    v-model="formData.orderDate"
                                                    type="datetime"
                                                    placeholder="选择日期时间">
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="档案号">
                                            <el-input v-model="formData.fileNumber"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="手机号码">
                                            <el-input v-model="formData.phoneNumber"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="预约类型">
                                            <el-input v-model="formData.orderType"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预约状态">
                                            <el-input v-model="formData.orderStatus"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            activeName: 'first',//添加/编辑窗口Tab标签名称
            checkbox: [],//多选框的数据
            dataList: [],//当前页要展示的分页列表数据
            setmealIds:[],//添加表单窗口中检查组复选框对应id
            tableData:[],//添加表单窗口中检查组列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
        },
        methods: {
            //批量删除预约信息
            BatchCancelled() {
                if (this.checkbox == undefined || this.checkbox.length <= 0) {
                    this.$message.warning("请选择您要取消的预约信息")
                } else {
                    this.$confirm("您确认要删除这些信息吗？", "提示", {
                        type: 'warning'
                    }).then(() => {
                        //将页面对象传给后台取消
                        axios.post("/orderlist/DeletOrder.do", this.checkbox).then((res) => {
                            console.log(this.checkbox);
                            if (res.data.flag) {
                                this.$message({
                                    message: res.data.message,
                                    type: "success"
                                });
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message)
                            }
                        });
                    });
                }
            },
            //获得多选框数据
            handleSelection(val) {
                this.checkbox = val;

            },
            //修改element ui日期组件获得的时间格式
            getDateTime(datetime) {
                this.formData.orderDate = datetime;
            },
            handleAdd() {
                //alert(this.checkitemIds);
                //发送ajax请求，将表单数据提交到后台进行处理
                axios.post("/orderlist/add.do?setmealIds="+this.setmealIds, this.formData).then((res) => {
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    if (res.data.flag) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //重新进行分页查询
                    this.findPage();
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();
                //发请求获取到所有套餐
                axios.post("/orderlist/findsetmeal.do").then((res)=>{
                    if(res.data.flag){
                        this.tableData=res.data.data;
                    }
                })
            },
            // 确认预约
            affirmOrder(row) {
                this.$confirm("这将确认此条预约信息，并将预约日期已短信形式发送给用户", "确认", {type: "success"}).then(() => {
                    //发短信并修改状态为已预约
                    axios.post("/orderlist/affirmOrder.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: "success"
                            });
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message)
                        }
                    });
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },

            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/orderlist/findPage.do", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination.total = res.data.data.total;
                    this.dataList = res.data.data.rows;
                    console.log(this.data)
                });
            },
            // 删除
            cancelOrder(row) {//row其实是一个json对象，json对象的结构为{"age":"0-100","attention":"无","code":"0011","id":38,"name":"白细胞计数","price":10.0,"remark":"白细胞计数","sex":"0","type":"2"}
                //alert(row.id);
                this.$confirm("你确定要取消预约吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/orderlist/cancelOrder.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>
</html>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:0,
                queryString:null,
            },
            formData: {},//表单数据
            dataList:[],//查询回的数据容器
            checkBoxData: [],    //多选框选择的值
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false//控制编辑窗口显示/隐藏
        },

        created() {
            this.findPage();
        },
        methods: {
            selectionChange(val){
                this.checkBoxData=val
                console.log(val)
            },
            //添加
            handleAdd () {
                //发送ajax请求，将表单数据（预约列表）提交到后台进行处理
                axios.post("/orderSettingList/addOrderSettingList.do",this.formData).then((res) => {
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    if(res.data.flag){
                        //执行成功
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                    }else{
                        //执行失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    this.findPage();
                });
            },
            //分页查询
            findPage() {
                //分页参数
                var param = {
                    currentPage:this.pagination.currentPage,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    queryString:this.pagination.queryString//查询条件 -++
                };
                //请求后台
                axios.post("/orderSettingList/findPage.do",param).then((response)=> {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {

                this.$confirm("你确定要取消当前预约吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将预约ID提交到Controller进行处理
                    axios.get("/orderSettingList/delete.do?id=" + row.id).then((res) => {
                        if(res.data.flag){
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r)=>{
                        this.showMessage(r);
                    });
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            },
            //批量取消预约
            handleDeletes() {

                this.$confirm("你确定要批量取消选中预约吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{

                    //用户点击确定按钮，发送ajax请求，将多选框数据提交到Controller进行处理
                    axios.post("/orderSettingList/deletes.do",this.checkBoxData).then((res) => {
                        if(res.data.flag){
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r)=>{
                        this.showMessage(r);
                    });
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            }
        },
    })
</script>
</html>
